package com.zhisuo.apicenter.util;

import com.alibaba.fastjson.JSONException;
import com.github.qcloudsms.TtsVoiceSender;
import com.github.qcloudsms.TtsVoiceSenderResult;
import org.apache.commons.logging.LogFactory;

import javax.xml.ws.http.HTTPException;
import java.io.IOException;

/**
 * Tencent Cloud Sms Sendsms
 * https://cloud.tencent.com/document/product/382/38778
 */
public class SendVoiceSmsUtil {
    public static final Integer APPID=1400449487;
    public static final String APPKEY="0eab4bce6d0becf9657527f873349387";
    //短信模板ID，需要在短信应用中申请
    //public static final Integer templateId=775921;
    // 签名
    public static final String smsSign = "智梭无人车";





    public static String sendSmsVideoPhoneCode( String[] params,  String[] phoneNumbers ) throws Exception{
        TtsVoiceSenderResult result =new TtsVoiceSenderResult ();
        int templateId = 775919;
        try {

            //验证码 params

            TtsVoiceSender tvsender = new TtsVoiceSender(APPID, APPKEY);
            result = tvsender.send("86", phoneNumbers[0],
                    templateId, params, 2, "");  // 签名不能为空串
            LogFactory.getLog(new SendVoiceSmsUtil().getClass()).info("sendSmsPhoneCode-----------------------:" +phoneNumbers[0] +result);
        } catch (HTTPException e) {
            // HTTP响应码错误
            e.printStackTrace();
        } catch (JSONException e) {
            // json解析错误
            e.printStackTrace();
        } catch (IOException e) {
            // 网络IO错误
            e.printStackTrace();
        }

        return result.toString();

    }




    public static void main(String[] args) throws Exception{
        try {

            //验证码
            String[] params = {"1","2"};
            String[] phoneNumbers = {"18602582663"};
            String result= SendVoiceSmsUtil.sendSmsVideoPhoneCode(params,phoneNumbers);// 签名不能为空串
            System.out.println(result);
        } catch (HTTPException e) {
            // HTTP响应码错误
            e.printStackTrace();
        } catch (JSONException e) {
            // json解析错误
            e.printStackTrace();
        } catch (IOException e) {
            // 网络IO错误
            e.printStackTrace();
        }
    }
}